﻿using System.Collections;
namespace System.Net.Util
{
    internal class DoubleLinkListEnumerator : IEnumerator
    {
        private DoubleLink _current;
        private DoubleLinkList _list;

        internal DoubleLinkListEnumerator(DoubleLinkList list)
        {
            _list = list;
            _current = list;
        }

        internal DoubleLink GetDoubleLink() { return _current; }

        public bool MoveNext()
        {
            if (_current.Next == _list)
            {
                _current = null;
                return false;
            }
            _current = _current.Next;
            return true;
        }

        public void Reset() { _current = _list; }

        public object Current
        {
            get
            {
                if ((_current == null) || (_current == _list))
                    throw new InvalidOperationException();
                return _current.Item;
            }
        }
    }
}
